package com.hexacta.hrs.services.feedbacks.impl;

import java.util.Collection;

import com.hexacta.hrs.domain.feedback.Period;
import com.hexacta.hrs.repositories.feedback.PeriodObjectRepository;
import com.hexacta.hrs.services.feedbacks.PeriodService;

public class PeriodServiceImpl implements PeriodService {

    private PeriodObjectRepository periodObjectRepository;

    public PeriodObjectRepository getPeriodObjectRepository() {
        return periodObjectRepository;
    }

    public void setPeriodObjectRepository(final PeriodObjectRepository periodObjectRepository) {
        this.periodObjectRepository = periodObjectRepository;
    }

    @Override
    public Collection<Period> findAll() {
        return periodObjectRepository.findAll();
    }

    @Override
    public void closePeriod(final Period period) {
        periodObjectRepository.closePeriod(period);
    }

    @Override
    public void closePeriod(final String year) {
        periodObjectRepository.closePeriod(year);
    }

    @Override
    public void openPeriod(final Period period) {
        periodObjectRepository.openPeriod(period);
    }

    @Override
    public void openPeriod(final String year) {
        periodObjectRepository.openPeriod(year);
    }

    @Override
    public Period getLastPeriod() {
        return periodObjectRepository.getLastPeriod();
    }

    @Override
    public Period getPeriodByYear(final String year) {
        return periodObjectRepository.getPeriodByYear(year);
    }

    @Override
    public void update(final Period period) {
        periodObjectRepository.save(period);
    }

    @Override
    public void save(final Period period) {
        periodObjectRepository.save(period);
    }

    @Override
    public void delete(final Long periodId) {
        Period period = periodObjectRepository.forId(periodId);
        periodObjectRepository.delete(period);
    }

    @Override
    public Period getOpenPeriod() {
        return periodObjectRepository.getOpenPeriod();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.hexacta.hrs.services.feedbacks.PeriodService#existsOpenPeriod()
     */
    @Override
    public boolean existsOpenPeriod() {
        return getOpenPeriod() != null;
    }

}
